import entry from '@/page/entry'
import layout from '@/page/layout'
import login from '@/page/user/login'

// 各个模块引入
// 【注意：各模块子页面，path、selectKeyUrl必须一致, name格式使用：'/模块路由名称/2级菜单路由名称'；子页面路由必须设置meta，包含字段openKeyName（1级菜单名称），selectKeyUrl（2级菜单路由名称）】
import salesCenterChildRoutes from '@/router/salesCenter'
import systemPersonnelManagementChildRoutes from '@/router/systemPersonnelManagement'
import shipCenterChildRoutes from '@/router/shipCenter'
import landCenterChildRoutes from '@/router/landCenter'
import supplierCenterChildRoutes from '@/router/supplierCenter'
import appManagementCenterChildRoutes from '@/router/appManagementCenter'
import boxManagementCenterChildRoutes from '@/router/boxManagementCenter'
import orderCenterChildRoutes from '@/router/orderCenter'
import financialCenterChildRoutes from '@/router/financialCenter'
import dataBIChildRoutes from '@/router/dataBI'

const routes = [
  {
    path: '/',
    redirect: '/entry'
  },
  {
    path: '/user/login',
    component: login,
    beforeEnter (to, from, next) {
      next()
    }
  },
  {
    path: '/entry',
    component: entry,
    beforeEnter (to, from, next) {
      next()
    }
  },
  {
    path: '/dataBI',
    component: layout,
    beforeEnter (to, from, next) {
      next()
    },
    children: dataBIChildRoutes
  },
  {
    path: '/salesCenter',
    component: layout,
    beforeEnter (to, from, next) {
      next()
    },
    children: salesCenterChildRoutes
  },
  {
    path: '/orderCenter',
    component: layout,
    beforeEnter (to, from, next) {
      next()
    },
    children: orderCenterChildRoutes
  },
  {
    path: '/financialCenter',
    component: layout,
    beforeEnter (to, from, next) {
      next()
    },
    children: financialCenterChildRoutes
  },
  {
    path: '/shipCenter',
    component: layout,
    beforeEnter (to, from, next) {
      next()
    },
    children: shipCenterChildRoutes
  },
  {
    path: '/landCenter',
    component: layout,
    beforeEnter (to, from, next) {
      next()
    },
    children: landCenterChildRoutes
  },
  {
    path: '/boxManagementCenter',
    component: layout,
    beforeEnter (to, from, next) {
      next()
    },
    children: boxManagementCenterChildRoutes
  },
  {
    path: '/supplierCenter',
    component: layout,
    beforeEnter (to, from, next) {
      next()
    },
    children: supplierCenterChildRoutes
  },
  {
    path: '/systemPersonnelManagement',
    component: layout,
    beforeEnter (to, from, next) {
      next()
    },
    children: systemPersonnelManagementChildRoutes
  },
  {
    path: '/appManagementCenter',
    component: layout,
    beforeEnter (to, from, next) {
      next()
    },
    children: appManagementCenterChildRoutes
  },
  {
    path: '/a',
    component: () => import('@/page/shipCenter/ceshi'),
    beforeEnter (to, from, next) {
      next()
    }
  },
  {
    // 此处必须写在正常route最后
    path: '*',
    component: () => import('@/page/404')
  }
]

export default {
  mode: 'history',
  routes,
  scrollBehavior (to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { x: 0, y: 0 }
    }
  }
}
